# 数据容器之list
"""
特点：有序、可重复、可修改
"""
import random
list1 = ['2', 1, "测试1"]
list1.append("测试2")
print(list1)
list2 = ["测试3", "测试4", "测试5"]
list1.extend(list2)
print(list1)
list1.insert(0, "good")
print(list1)
del list1[-1]
print(list1)



# 数据容器之tuple
"""
特点：有序、可重复、不可修改
"""


# 数据容器之str
"""
特点：不可修改，只能是字符串："xxx"
"""

# 数据容器之set
"""
特点：无序、不可重复、可修改
由于无序，所以其内元素无下标，不可使用while循环进行遍历，只能通过for循环进行遍历
"""
set1 = {"测试1", "测试2", "测试3", "测试1"}
print(set1)
set1.add("测试4")
print(set1)
set1.remove("测试2")
print(set1)
set1.pop()
print(set1)
set1.add("测试2")
set2 = {"测试10", "测试9", "测试2"}
# 取set1中不存在与set2的数据，形成一个新的集合
set3 = set1.difference(set2)
print(set1)
print(set2)
print(set3)
set1.difference_update(set2)
print(set1)
set1 = {"测试1", "测试2", "测试3"}
set2 = {"测试3", "测试4", "测试5"}
set3 = set1.union(set2)
print(set3)

print(len(set3))


# 集合测试小案例
list1 = ["测试1", "测试2", "测试3", "测试4", "测试3", "测试2", "测试5"]
set1 = set()
for element in list1:
    set1.add(element)

print(set1)


# 字典的操作
# 定义空字典
dict1 = {}
dict1 = dict()
print(type(dict1))

# 定义简单字典
dict1 = {"姓名": 18, "年龄": "张三", "性别": "唱跳rap"}
print(dict1["姓名"])

# 定义嵌套字典
dict1 = {
    "姓名":"18",
    "年龄": "张三",
    "爱好":{
        "唱": "跳舞",
        "跳": "唱歌"
    }
}
print(dict1["爱好"]["唱"])

dict1 = {"姓名": 18, "年龄": "张三", "性别": "唱跳rap"}
dict1["爱好"] = "美女"
print(dict1)

dict1["姓名"] = 25
print(dict1)


# 字典测试小案例
dict1 = {
    "王力鸿": {
        "部门": "科技部",
        "工资": 3000,
        "级别": 1
    },
    "周杰伦": {
        "部门": "市场部",
        "工资": 5000,
        "级别": 2
    },
    "林俊结": {
        "部门": "市场部",
        "工资": 7000,
        "级别": 3
    }
}

print(dict1)

for employee in dict1:
    # 这里的employee是dict1中的key值
    if (dict1[employee]["级别"] == 1):
        dict1[employee]["级别"] = 2
        dict1[employee]["工资"] += 1000
print(dict1)

# 删除元素
dict1 = {"姓名": 18, "年龄": "张三", "性别": "唱跳rap"}
dict1.pop("姓名")
print(dict1)
print(dict1.keys())
for key in dict1.keys():
    print(key)

print(len(dict1))
print(dict1.clear())



